
/**
 * Object that serves as a node in the minheap used in the
 * implementation of Prim's Algorithm. Each vertex in a
 * SimpleGraph is associated with a single vertex and vice versa.
 * 
 * @author Chris Davidson, Michelle Miller, and Agari Nln
 * @version Winter 2012.
 */
public class PrimHeapNode implements Comparable<PrimHeapNode> {

	/** A reference to the vertex object that this node is associated. */
	private final Vertex my_vertex;
	
	/** 
	 * A reference to the position in the minheap backing store
	 * array that this node occupies.
	 */
	private int my_heap_position;
	
	/**
	 * Constructor for a PrimHeapNode that accepts a vertex to contain
	 * a reference to.
	 * 
	 * @param the_vertex The vertex to contain a reference to.
	 */
	public PrimHeapNode(final Vertex the_vertex) {
		my_vertex = the_vertex;
	}
	
	/**
	 * Returns a reference to this node's vertex.
	 * 
	 * @return A reference to this node's vertex.
	 */
	public Vertex getVertex() {
		return my_vertex;
	}
	
	/**
	 * Returns this node's position within the minheap backing store array.
	 * 
	 * @return This node's position within the minheap backing store array.
	 */
	public int getHeapPosition() {
		return my_heap_position;
	}
	
	/**
	 * Sets the provided heap position as this node's new heap position.
	 * 
	 * @param the_new_position The int to set as the new heap position.
	 */
	public void setHeapPosition(final int the_new_position) {
		my_heap_position = the_new_position;
	}
	
	/* 
	 * This implementation of the compareTo method relies on the values of the
	 * label's of the node's vertex reference.
	 */
	@Override
	public int compareTo(final PrimHeapNode the_node) {
		final Double this_label = ((PrimVertexData) my_vertex.getData()).getLabel();
		final Double other_label = ((PrimVertexData) the_node.getVertex().getData()).getLabel();
		return this_label.compareTo(other_label);
	}

}
